<%--
  Created by IntelliJ IDEA.
  User: yz_yang
  Date: 2019/2/17
  Time: 20:22
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../resources/ico/favicon.ico">

    <title>Login</title>

    <link rel="stylesheet" href="../../resources/css/lib/bootstrap.min.css">

    <!-- Custom styles for this template -->
    <link href="../../resources/css/login.css" rel="stylesheet">
    <script src="../../resources/js/jquery-3.3.1.min.js"></script>
    <style type="text/css">
        #formPos{
            position: absolute;
            top: 25%;
            left: 25%;
            width: 50%;
            height: 50%;
        }
    </style>


    <script>
        $(document).ready(function () {
            $("#errorInf").hide();
            $("#submit").click(function () {
                //alert("click!")
                var params = {};
                params.username = $("#username").val();
                params.password = $("#password").val();
                $.ajax({
                    type: "POST",
                    url: "login",//注意路径
                    data: params,
                    dataType: "json",
                    success: function (data) {
                        if(data.result==="SUCCESS"){
                            var len=document.location.href.length;
                            document.location.href=document.location.href.substr(0,len-5)+"puzzleType";
                        }
                        else{
                            $("#errorInf").show();
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            });
        });
    </script>
</head>

<body>
<div class="container">
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <a class="navbar-brand">
                    Login
                </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="/exit">Back</a></li>
                </ul>
            </div>
        </div>
    </nav>

    <div id="formPos">
        <form class="form-signin">
            <div id="errorInf" style="color: red; font-size: medium; font-family: Arial">Invalid username or password!</div>
            <h2 class="form-signin-heading">Please sign in</h2>
            <label for="username" class="sr-only">User name</label>
            <input type="text" id="username" class="form-control" placeholder="User name" required autofocus>
            <label for="password" class="sr-only">Password</label>
            <input type="password" id="password"  class="form-control" placeholder="Password" required>
            <button class="btn btn-lg btn-primary btn-block" type="button" id="submit">Login</button>
        </form>

    </div>
</div> <!-- /container -->

</body>
</html>